﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace JdFormsDll
{
    public partial class MyFormEditor : MyForm
    {

        public MyFormEditor()
        {
            InitializeComponent();
        }

        private Size size;
        public MyForm Form { get; set; }

        private void MyFormEditor_Load(object sender, EventArgs e)
        {
            size = this.Size;
            if (Decorator.Form == null) Decorator.Form = this;
            Decorator.OnLoad += new Load(Decorator_OnLoad);
            Decorator.OnSave += new Save(Decorator_OnSave);
            propertyGrid1.SelectedObject = this.Decorator.Form;
            label1.Text = "Decorator from Design";
        }

        private void Decorator_OnLoad(object sender, DecoratorEventArgs e)
        {
        	this.SetParameters(e.FileName);
        }

        private void Decorator_OnSave(object sender, DecoratorEventArgs e)
        {
        	this.SetParameters(e.FileName);
        }
        
        private void SetParameters(string filename)
        {
        	this.Size = size;
            propertyGrid1.Refresh();
            if(Decorator.Form == this)
            {
                label1.Text = "Decorator from " + Path.GetFileNameWithoutExtension(filename);
                this.Refresh();
            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
          if( this.Decorator.Open() == DialogResult.Cancel )
              MyFormMessageBox .Show (this,"Operation Cancelled by User !!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.Decorator.Save() == DialogResult.Cancel)
                MyFormMessageBox.Show(this, "Operation Cancelled by User !!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnDir_Click(object sender, EventArgs e)
        {
            this.Decorator.OpenDecoratorFolder();
        }
    }
}
